﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKArchMethodLibrary.Utils;

namespace ColumnModuleAndEdit.DataDefine
{
	public class ColumnDatum
	{
		public FamilySymbol ColSym
		{
			get
			{
				return this.m_ColSym;
			}
			set
			{
				this.m_ColSym = value;
			}
		}

		public double Angle
		{
			get
			{
				return this.m_dAng;
			}
			set
			{
				this.m_dAng = value;
			}
		}

		public ElementId MateralId
		{
			get
			{
				return this.m_materalId;
			}
			set
			{
				this.m_materalId = value;
			}
		}

		public double BottomOffset
		{
			get
			{
				return Common.MMToFeet(this.m_dBottomOffset);
			}
			set
			{
				this.m_dBottomOffset = value;
			}
		}

		public double TopOffset
		{
			get
			{
				return Common.MMToFeet(this.m_dTopOffset);
			}
			set
			{
				this.m_dTopOffset = value;
			}
		}

		public Level Toplevel
		{
			get
			{
				return this.m_Toplevel;
			}
			set
			{
				this.m_Toplevel = value;
			}
		}

		public Level Bottomlevel
		{
			get
			{
				return this.m_Bottomlevel;
			}
			set
			{
				this.m_Bottomlevel = value;
			}
		}

		public bool IsArch
		{
			get
			{
				return this.m_bIsArch;
			}
			set
			{
				this.m_bIsArch = value;
			}
		}

		public void SetTopBottomOffset(double dHeight, double dBaseOffset)
		{
			this.m_dBottomOffset = dBaseOffset;
			List<Level> sortLevels = Common.GetSortLevels(this.m_doc, double.MinValue, double.MaxValue);
			int num = sortLevels.FindIndex((Level level) => this.m_Bottomlevel.Id == level.Id);
			if (num == -1)
			{
				return;
			}
			double num2 = dHeight + this.m_dBottomOffset;
			if (Geometry.LessThan(num2, 0.0))
			{
				for (int i = num; i < sortLevels.Count; i++)
				{
					double val = sortLevels[i].Elevation - this.m_Bottomlevel.Elevation;
					if (!Geometry.LessThan(val, num2))
					{
						this.m_Toplevel = sortLevels[i];
						break;
					}
				}
				if (this.m_Toplevel == null)
				{
					this.m_Toplevel = sortLevels[sortLevels.Count - 1];
				}
			}
			else
			{
				for (int j = num; j < sortLevels.Count; j--)
				{
					double val2 = sortLevels[j].Elevation - this.m_Bottomlevel.Elevation;
					if (Geometry.LessThan(val2, num2))
					{
						this.m_Toplevel = sortLevels[j];
						break;
					}
				}
			}
			this.m_dTopOffset = dHeight + this.m_dBottomOffset + this.m_Bottomlevel.Elevation - this.m_Toplevel.Elevation;
		}

		public ColumnDatum(Document doc)
		{
			this.m_doc = doc;
			this.initData();
		}

		private void initData()
		{
			this.m_ColSym = null;
			this.m_materalId = ElementId.InvalidElementId;
			this.m_dBottomOffset = 0.0;
			this.m_dTopOffset = 0.0;
			this.m_dAng = 0.0;
			this.m_Bottomlevel = this.m_doc.ActiveView.GenLevel;
			this.m_Toplevel = null;
		}

		private FamilySymbol m_ColSym;

		private ElementId m_materalId;

		private double m_dBottomOffset;

		private double m_dTopOffset;

		private double m_dAng;

		private Level m_Bottomlevel;

		private Level m_Toplevel;

		private bool m_bIsArch;

		private Document m_doc;
	}
}
